package Attribute::SubName;

use strict;
use warnings;
use Sub::Name;
use base 'Attribute::Handlers';


our $VERSION = '0.02';


sub UNIVERSAL::Name : ATTR(CODE) {
   my ($package, $symbol, $referent, $attr, $data, $phase) = @_;
   my $name = "${package}::${data}";
   subname $name => $referent;
   no strict 'refs';
   *{$name} = $referent;
}


1;


__END__

{% USE p = PodGenerated %}

=head1 NAME

{% p.package %} - Naming anonymous subroutines via attributes

=head1 SYNOPSIS

    use {% p.package %};

    my $coderef = sub :Name(foo) { ... };

    print foo(...);

=head1 DESCRIPTION

This module provides an attribute C<:Name> that you can use on anonymous
subroutines to give them a name. This is useful as they will then show up with
that name in stack traces (cf. L<Carp>). The naming is done with L<Sub::Name>.
Additionally, the attribute also installs the newly named subroutine in the
proper glob slot so you can refer to it by name.

{% PROCESS standard_pod %}

=cut

